package org.openotdr.server.file.xml;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

public abstract class ChartParser {

	abstract protected Integer getYaxis(Integer iChart);
	abstract protected Integer getXaxis(Integer iChart);
	abstract protected Integer getChartCount();
	abstract protected String getName(Integer iChart);
	
	public void parse(Document document, Element root) {
		Element chartRoot = document.createElement("Chart");
		root.appendChild(chartRoot);
		
		// Chart
		for (Integer iChart = 0; iChart < getChartCount(); iChart++) {
			Element chart = document.createElement("ChartElement");
			chartRoot.appendChild(chart);
			chart.setAttribute("ID", iChart.toString());
			chart.setAttribute("Name", getName(iChart));
			Element x = document.createElement("XAxis");
			chart.appendChild(x);
			Text xVal = document.createTextNode(getXaxis(iChart).toString());
			x.appendChild(xVal);
			
			Element y = document.createElement("YAxis");
			chart.appendChild(y);
			Text yVal = document.createTextNode(getYaxis(iChart).toString());
			y.appendChild(yVal);
		}
	}

}
